package braden.cis.uab.edu.automaton;

import java.util.HashSet;

public class Transition {

	private State startState;
	private State endState;
	private HashSet<Character> labels;
	private float endX;
	private float endY;
	private boolean hasOpposite;
	
	public Transition(State startState) {

		this.startState = startState;
		this.hasOpposite = false;
		this.labels = new HashSet<Character>();
	}
	
	public Transition(State startState, State endState) {

		this.startState = startState;
		this.setEndState(endState);
		this.hasOpposite = false;
		this.labels = new HashSet<Character>();
		labels.add('ɛ');
	}
	
	public Transition(State startState, State endState, char label) {

		this.startState = startState;
		this.setEndState(endState);
		this.hasOpposite = false;
		this.labels = new HashSet<Character>();
		labels.add(label);
	}

	public boolean hasOpposite() {
		return hasOpposite;
	}

	public void setHasOpposite(boolean hasOpposite) {
		this.hasOpposite = hasOpposite;
	}

	public void setStartState(State startState) {
		this.startState = startState;
	}
	
	public void setEndState(State endState) {
		this.endState = endState;
		int graphicWidth = this.endState.getGraphic().getWidth();
		int graphicHeight = this.endState.getGraphic().getHeight();
		this.endX = this.endState.getX() + (graphicWidth / 2);
		this.endY = this.endState.getY() + (graphicHeight / 2);
	}

	public float getEndX() {
		if (endState != null) {
			return endState.getX() + (endState.getGraphic().getWidth() / 2);
		} else {
			return endX;
		}
	}

	public float getEndY() {
		if (endState != null) {
			return endState.getY() + (endState.getGraphic().getHeight() / 2);
		} else {
			return endY;
		}
	}

	public void setEndX(float endX) {
		this.endX = endX;
	}

	public void setEndY(float endY) {
		this.endY = endY;
	}

	public float getStartX() {
		return this.startState.getX()
				+ (this.startState.getGraphic().getWidth() / 2);
	}

	public float getStartY() {
		return this.startState.getY()
				+ (this.startState.getGraphic().getHeight() / 2);
	}

	public State getStartState() {
		return this.startState;
	}

	public State getEndState() {
		return this.endState;
	}

	public HashSet<Character> getLabels() {
		return labels;
	}

	public String getLabelString() {
			return labels.toString();
	}

	public void addLabel(char c) {
		labels.add(c);
	}

	public void removeLabel(char c) {
		labels.remove(c);
	}

	public void removeLabels(HashSet<Character> toRemove) {
		labels.removeAll(toRemove);
	}

	public void addLabels(HashSet<Character> newCharacters) {
		labels.addAll(newCharacters);
	}
	
	public void clearLabels() {
		this.labels = new HashSet<Character>();
	}
}